<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
use Think\Page;
class IndexController extends CommonController {
    
	var $catelist = array(
				'player'=>3,
				'wsq-img'=>1,
				'wsq-list'=>3,
				'travel-img'=>1,
				'travel-list'=>3,
				'home'=>4,
				'education'=>4,
				'life'=>4,
				'food'=>4,
				'act-join-list'=>4,
				'act-join-img'=>1,
				'act-pre'=>2,
				'act-review-list'=>3,
				'act-review-img'=>1,
				'index-left-ad'=>2,
				'index-right-ad'=>2,
				'left-ad-a'=>1,
				'left-ad-b'=>1
			);
	
	public function index(){
    	
    	$push = M('PushData');
    	
    	foreach ($this->catelist as $key => $val){
    		
    		$pushdata = $push ->where('flag="'.$key.'" and status=0' )->limit($val)->order('orderby,id desc') ->select();
    		$pushdata_list[$key] = $pushdata;
    	}
    	$this->assign('pushdata_list',$pushdata_list);
    	//var_dump($pushdata_list);
    	
    	$link = M('Link'); 
    	$linklist = $link->where('status=0' ) ->limit(24)->order('orderby,id desc')->select();
    	$this->assign('link_list',$linklist);
    	
    	$catelist = M('ArticleCate')->order('orderby')->select();
		$this->assign('catelist',$catelist);
    	
		$this->assign('is_index',TRUE);
		
		$this->display('Index/index');
    }
    
    
	public function search(){
			
			$push = D('PushData'); // 实例化User对象
			
			$name = $_GET['keyword'];
			
			
			if ($name == NULL){
				$this->redirect('Index/index');
			}else {
				$map['status'] = array('eq','0');
				$map['name'] = array('like','%'.$name.'%');
				$count      = $push-> where($map)->count();// 查询满足要求的总记录数
				$parameter=array(
					'status'=>'0',
					'name'=>$name,
				);
				$Page       = new Page($count,6,$parameter);// 实例化分页类 传入总记录数和每页显示的记录数
				$show       = $Page->show();// 分页显示输出
				$list = $push-> where($map) -> limit($Page->firstRow.','.$Page->listRows)->order('created_at desc')->select();
				$this->assign('data',$list);// 赋值数据集
				$this->assign('page',$show);// 赋值分页输出
				
				//获取主页 幻灯列表 
		    	$slide = M('Slide'); 
				$slidelist = $slide->where('status=0')->limit(3)->order('created_at desc')-> select();
				$this->assign('slidelist',$slidelist);
				
				$advert = M('Advert'); 
				$advertlist = $advert->where('status=0')->limit(4)->order('created_at desc')-> select();
				$this->assign('advertlist',$advertlist);
				
				$this->assign('keyword',$name);
				$this->display('Index/search');
			}
			
	}
	
	public function area(){
			
		$push = D('PushData'); // 实例化User对象
		
		$areaid = $_GET['id'];
		
		$map['status'] = array('eq','0');
		$map['areaid'] = array('eq',$areaid);
		$count      = $push-> where($map)->count();// 查询满足要求的总记录数
		$parameter=array(
			'id'=>$areaid,
		);
		$Page       = new Page($count,6,$parameter);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$list = $push-> where($map) -> limit($Page->firstRow.','.$Page->listRows)->order('created_at desc')->select();
		$this->assign('data',$list);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		
		$areaname = M('HouseArea')->where('id='.$areaid)->getField('areaname');
		$this->assign('areaname',$areaname);
		
		//获取主页 幻灯列表 
    	$slide = M('Slide'); 
		$slidelist = $slide->where('status=0')->limit(3)->order('created_at desc')-> select();
		$this->assign('slidelist',$slidelist);
		
		$this->display('Index/area');
	}
    
    
	public function show(){
    	$id=$_GET['id'];
    	$push = D('PushData');
    	$PushData = $push -> relation(true) ->find($id);
    	$this->assign('PushData',$PushData);
    	
    	//获取主页 幻灯列表 
    	$slide = M('Slide'); 
		$slidelist = $slide->where('status=0')->limit(3)->order('created_at desc')-> select();
		$this->assign('slidelist',$slidelist);
		
		$advert = M('Advert'); 
		$advertlist = $advert->where('status=0')->limit(10)->order('created_at desc')-> select();
		$this->assign('advertlist',$advertlist);
		
		$this->display('Index/show');
    }
}